<script type="text/javascript" src="__PUBLIC__/js/jquery.validate.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/jQuery-jcDate.js"></script>
<script type="text/javascript" src="__PUBLIC__/layer/layer.js"></script>
<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/form_v.css">

<style>
    input.error { border: 1px solid red; }
</style>
<script>
    (function($){
        $().ready(function(){
            $("input.jcDate").jcDate({
                IcoClass : "jcDateIco",
                Event : "click",
                Speed : 100,
                Left : 0,
                Top : 28,
                format : "-",
                Timeout : 100
            });

            //步骤数
            var  step_claims = step_gifts = '';
            var step_num=eval($("input[name='step_num']").val());

            for(var i=0;i<step_num;i++){
                step_claims+='<p><span class="reportTit">任务'+(i+1)+'要求：    </span><input type="text" class="inp" placeholder="请输入任务'+(i+1)+'要求..."></p>';
                step_gifts+='<p><span class="reportTit">任务'+(i+1)+'奖励：    </span><input type="text" class="inp" placeholder="请输入任务'+(i+1)+'奖励..."></p>';
            }
            $('.stepClaimMore').html(step_claims);
            $('.stepGiftMore').html(step_gifts);

            var desc_step_claim='<?php echo json_encode($ad["step_claim"]);?>';
            desc_step_claim=JSON.parse(desc_step_claim);

            var desc_step_gift='<?php echo json_encode($ad["step_gift"]);?>';
            desc_step_gift=JSON.parse(desc_step_gift);
            //console.log(desc);

            for(var i=0;i<desc_step_claim.length;i++){  //默认显示图片说明
                $('.stepClaimMore p').eq(i).find('input').val(desc_step_claim[i]);
                $('.stepClaimMore p').eq(i).find('input').attr('name','step_gift'+(i+1)+'');
                $('.stepClaimMore p').eq(i).find('input').attr('title','请输入任务'+(i+1)+'奖励');
                $('.stepClaimMore p').eq(i).find('input').attr('required','required');
            }

            for(var i=0;i<desc_step_gift.length;i++){  //默认显示图片说明
                $('.stepGiftMore p').eq(i).find('input').val(desc_step_gift[i]);
                $('.stepGiftMore p').eq(i).find('input').attr('name','step_claim'+(i+1)+'');
                $('.stepGiftMore p').eq(i).find('input').attr('title','请输入任务'+(i+1)+'要求');
                $('.stepGiftMore p').eq(i).find('input').attr('required','required');
            }

            $("input[name='step_num']").on('input',function(){

                var picExplain=parseInt($(this).val());
                var picCon=giftCon='';

                for(var i=0;i<picExplain;i++){
                    if(desc_step_claim[i]==undefined){        //没有图片说明时 ，显示默认
                        picCon+='<p><span class="reportTit">任务'+(i+1)+'要求：  </span><input type="text" class="inp" placeholder="请输入任务'+(i+1)+'要求..." name="step_claim'+(i+1)+'" title="请输入任务'+(i+1)+'要求" required></p>';
                        giftCon+='<p><span class="reportTit">任务'+(i+1)+'奖励：    </span><input type="text" class="inp" placeholder="请输入任务'+(i+1)+'奖励..." name="step_gift'+(i+1)+'" title="请输入任务'+(i+1)+'奖励" required></p>';
                    }else{                         //有图片说明时，显示说明
                        picCon+='<p><span class="reportTit">任务'+(i+1)+'要求：    </span><input type="text" class="inp" value="'+desc_step_claim[i]+'" name="step_claim'+(i+1)+'" title="请输入任务'+(i+1)+'要求" required></p>';
                        giftCon+='<p><span class="reportTit">任务'+(i+1)+'奖励：    </span><input type="text" class="inp" value="'+desc_step_gift[i]+'" name="step_gift'+(i+1)+'" title="请输入任务'+(i+1)+'奖励" required></p>';
                    }

                }

                $('.stepClaimMore').html(picCon);
                $('.stepGiftMore').html(giftCon);

                $('.stepClaimMore').on('keyup','input',function(){
                    var picNameIndex=$(this).parent('p').index();

                    if(!$(this).val()==''){
                        $(this).attr('name','step_claim'+(picNameIndex+1));
                    }else{
                        $(this).removeAttr('name');
                    }
                })

                $('.stepGiftMore').on('keyup','input',function(){
                    var picNameIndex=$(this).parent('p').index();

                    if(!$(this).val()==''){
                        $(this).attr('name','step_gift'+(picNameIndex+1));
                    }else{
                        $(this).removeAttr('name');
                    }
                })

                return false;

            });

            //体验攻略步骤数
            var  raiders_explains = raiders_pictures = '';
            var raiders_num=eval($("input[name='raiders_num']").val());

            for(var i=0;i<raiders_num;i++){
                raiders_explains+='<p><span class="reportTit">体验攻略'+(i+1)+'说明：    </span><input type="text" class="inp" placeholder="请输入体验攻略'+(i+1)+'说明..."></p>';
                raiders_pictures+='<p><span class="reportTit">体验攻略'+(i+1)+'图片：    </span><input type="file" class="inp" value=""><a target="_blank" href="">当前图片</a></p>';
            }
            $('.raidersExplainMore').html(raiders_explains);
            $('.raidersPictureMore').html(raiders_pictures);

            //取值
            var desc_raiders_explain='<?php echo json_encode($ad["raiders_explain"]);?>';
            desc_raiders_explain=JSON.parse(desc_raiders_explain);

            var desc_raiders_picture='<?php echo json_encode($ad["raiders_picture"]);?>';
            desc_raiders_picture=JSON.parse(desc_raiders_picture);
            console.log(desc_raiders_picture);

            for(var i=0;i<desc_raiders_explain.length;i++){  //体验攻略说明
                $('.raidersExplainMore p').eq(i).find('input').val(desc_raiders_explain[i]);
                $('.raidersExplainMore p').eq(i).find('input').attr('name','raiders_explain'+(i+1)+'');
                $('.raidersExplainMore p').eq(i).find('input').attr('title','请输入体验攻略'+(i+1)+'说明');
                $('.raidersExplainMore p').eq(i).find('input').attr('required','required');
            }

            for(var i=0;i<desc_raiders_picture.length;i++){  //体验攻略图片
                //$('.raidersPictureMore p').eq(i).find('input').val(desc_raiders_picture[i]);
                $('.raidersPictureMore p').eq(i).find('a').attr('href','__ROOT__'+desc_raiders_picture[i]);
                $('.raidersPictureMore p').eq(i).find('input').attr('name','raiders_picture'+(i+1)+'');
                $('.raidersPictureMore p').eq(i).find('input').attr('title','请上传体验攻略'+(i+1)+'图片');
                //$('.raidersPictureMore p').eq(i).find('input').attr('required','required');
            }

            $("input[name='raiders_num']").on('input',function(){

                var raidersExplain=parseInt($(this).val());
                var explain=picture='';

                for(var i=0;i<raidersExplain;i++){
                    if(desc_raiders_explain[i]==undefined){        //没有图片说明时 ，显示默认
                        explain+='<p><span class="reportTit">体验攻略'+(i+1)+'说明：  </span><input type="text" class="inp" placeholder="请输入体验攻略'+(i+1)+'要求..." name="raiders_explain'+(i+1)+'" title="请输入任务'+(i+1)+'要求" required></p>';
                        picture+='<p><span class="reportTit">体验攻略'+(i+1)+'图片：    </span><input type="file" class="inp" name="raiders_picture'+(i+1)+'" title="请上传体验攻略'+(i+1)+'图片" required></p>';
                    }else{                         //有图片说明时，显示说明
                        explain+='<p><span class="reportTit">体验攻略'+(i+1)+'说明：    </span><input type="text" class="inp" value="'+desc_raiders_explain[i]+'" name="raiders_explain'+(i+1)+'" title="请输入任务'+(i+1)+'要求" required></p>';
                        picture+='<p><span class="reportTit">体验攻略'+(i+1)+'图片：    </span><input type="file" class="inp" name="raiders_picture'+(i+1)+'"><a target="_blank" href="__ROOT__'+desc_raiders_picture[i]+'">当前图片</a></p>';
                    }

                }

                $('.raidersExplainMore').html(explain);
                $('.raidersPictureMore').html(picture);

                $('.raidersExplainMore').on('keyup','input',function(){
                    var picNameIndex=$(this).parent('p').index();

                    if(!$(this).val()==''){
                        $(this).attr('name','raiders_explain'+(picNameIndex+1));
                    }else{
                        $(this).removeAttr('name');
                    }
                })

                $('.raidersPictureMore').on('keyup','input',function(){
                    var picNameIndex=$(this).parent('p').index();

                    if(!$(this).val()==''){
                        $(this).attr('name','raiders_picture'+(picNameIndex+1));
                    }else{
                        $(this).removeAttr('name');
                    }
                })

                return false;

            });

        })
    })(jQuery);
    function showRuleEx()
    {
        var content = '<p>*在体验过程中如有以下违规行为，将得不到U币奖励，严重者直接冻结帐号：</p>'+
                '<p>1.创建试玩账号昵称、角色名称不得跟聚享游内容相关。</p>'+
                '<p>2.严禁在投资平台里发表任何有关聚享游的话题，如“做任务、聚享游”等。</p>'+
                '<p>3.不要在投资平台里发表诋毁商家的言论，如“垃圾平台、平台太烂、拿完奖励不投资”等。</p>'+
                '<p>4.为了快速获取U币奖励，使用第三方软件进行注册投资。</p>'+
                '<p>5.严禁注册多个聚享游账号参与平台注册或投资以非法获取U币奖励。</p>'+
                '<p>6.不要在投资平台里推荐其他玩家加入聚享游，以免对合作商家造成影响。</p>';
        layer.open({
            type: 1,
            shade: false, //不显示遮罩
            title: '<span style="color: red">试玩规则事例：</span>(可拖动)',
            skin: 'layer-ext-moon', //不用边框
            area: ['700px', '200px'], //宽高
            content: content
        });
    }
</script>
<h1 class="sysPageHead">
    <span class="sysPageDot"><img src="__PUBLIC__/images/sysListIcon3.png"><span class="textHide">.</span></span>
    广告编辑
</h1>

<div class="iotSysmCon" style="background:#fff">
    <!--  -->
    <form method="post" action="__ROOT__/index.php/Admin/Advertising/update" enctype="multipart/form-data" id="addActivityForm" class="cmxform">
        <input type="hidden" name="advertising_id" value="{$ad['advertising_id']}"/>
        <div class="reportCon picRelate ">
            <div class="reportBody">
                <div class="reportList"><span class="reportTit">广告名称：</span><input type="text" class="inp" name="advertising_name" id="advertising_name" placeholder="输入广告名称" title="请输入广告名称" value="{$ad['advertising_name']}" required></div>
                <div class="reportList">
                    <span class="reportTit" >广告主网站logo：</span>
                    <input type="file" class="inp" name="logo"><a target="_blank" href="__ROOT__{$ad['logo']}">当前图片</a>
                </div>
                <div class="reportList"><span class="reportTit">预期年化收益率：</span><input type="text" class="inp" name="rate" placeholder="请输入预期年化收益率" title="请输入预期年化收益率" required value="{$ad['rate']}"></div>
                <div class="reportList"><span class="reportTit">起购金额：</span><input type="text" class="inp" name="money" placeholder="请输入起购金额" title="请输入起购金额" required value="{$ad['money']}"></div>
                <div class="reportList"><span class="reportTit">平台名称：</span><input type="text" class="inp" name="platform" placeholder="请输入平台名称" title="请输入平台名称" required value="{$ad['platform']}"></div>
                <div class="reportList"><span class="reportTit">安全评级：</span><input type="text" class="inp" name="safe_rating" placeholder="请输入安全评级" title="请输入安全评级" required value="{$ad['safe_rating']}"></div>
                <div class="reportList"><span class="reportTit">网站地址：</span><input type="text" class="inp" name="siteUrl" placeholder="请输入网站地址" title="请输入网站地址" required value="{$ad['siteUrl']}"></div>
                <div class="reportList"><span class="reportTit">注册资金：</span><input type="text" class="inp" name="registered_capital" placeholder="请输入注册资金" title="请输入注册资金" required value="{$ad['registered_capital']}"></div>
                <div class="reportList"><span class="reportTit">所在地区：</span><input type="text" class="inp" name="region" placeholder="请输入所在地区" title="请输入所在地区" required value="{$ad['region']}"></div>
                <div class="reportList"><span class="reportTit">上线时间：</span>
                    <input type="text" class="inp jcDate" name="online_time" placeholder="请输入上线时间" title="请输入上线时间" required value="{$ad['online_time']}">
                </div>
                <div class="reportList"><span class="reportTit">ICP备案：</span><input type="text" class="inp" name="icp" placeholder="请输入ICP备案" title="请输入ICP备案" required value="{$ad['icp']}"></div>
                <div class="reportList"><span class="reportTit">联系电话：</span><input type="text" class="inp" name="phone" placeholder="请输入联系电话" title="请输入联系电话" required value="{$ad['phone']}"></div>
                <div class="reportList"><span class="reportTit">服务邮箱：</span><input type="text" class="inp" name="service_email" placeholder="请输入服务邮箱" title="请输入服务邮箱" required value="{$ad['service_email']}"></div>
                <div class="reportList"><span class="reportTit">公司信息：</span><textarea class="inp" name="company_info" required title="请输入公司信息" placeholder="请输入公司信息">{$ad['company_info']}</textarea></div>
                <div class="reportList"><span class="reportTit">立即体验跳转地址：</span><input type="text" class="inp" name="jump_url" placeholder="请输入立即体验跳转地址" title="请输入立即体验跳转地址" required value="{$ad['jump_url']}"></div>
                <div class="reportList">
                    <span class="reportTit">介绍图片：</span>
                    <input type="file" class="inp" name="introduce_picture"><a target="_blank" href="__ROOT__{$ad['introduce_picture']}">当前图片</a>
                </div>
                <div class="reportList"><span class="reportTit">温馨提示：</span><textarea class="inp" name="prompt" required placeholder="请输入温馨提示" title="请输入温馨提示">{$ad['prompt']}</textarea></div>
                <div class="reportList"><span class="reportTit">体验时间：</span><input type="text" class="inp jcDate" name="experience_time" placeholder="请输入体验时间" title="请输入体验时间" required value="{$ad['experience_time']}"></div>
                <div class="reportList"><span class="reportTit">发送方式：</span><input type="text" class="inp" name="send_method" placeholder="请输入发送方式" title="请输入发送方式" required value="{$ad['send_method']}"></div>
                <div class="reportList"><span class="reportTit" style="color: red">步骤数：</span><input type="text" class="inp" name="step_num" placeholder="请输入步骤数" title="请输入步骤数" required value="{$ad['step_num']}"></div>
                <div class="reportList">
                    <div class="stepClaimMore">

                    </div>
                </div>
                <div class="reportList">
                    <div class="stepGiftMore">

                    </div>
                </div>
                <div class="reportList"><span class="reportTit" style="color: red">体验攻略步骤数：</span><input type="text" class="inp" name="raiders_num" placeholder="请输入体验攻略步骤数" title="请输入体验攻略步骤数" required value="{$ad['raiders_num']}"></div>

                <div class="reportList">
                    <div class="raidersExplainMore">

                    </div>
                </div>
                <div class="reportList">
                    <div class="raidersPictureMore">

                    </div>
                </div>
                <div class="reportList"><span class="reportTit">试玩规则：</span><textarea class="inp" name="rule" required placeholder="请输入试玩规则" title="请输入试玩规则">{$ad['rule']}</textarea>&nbsp;<a href="javascript:void (0)" onclick="showRuleEx()">填写规则请参照此处</a></div>
                <div class="reportList"><span class="reportTit">广告类型：</span>
                    <select name="type" id="type" class="inp" required title="请选择广告类型" style="width: 810px">
                        <option value="">请选择</option>
                        <foreach name="ad_types" item="val" key="key">
                            <?php
                                $actived = '';
                                if ($key == $ad['type'])
                                {
                                    $actived = 'selected';
                                }
                            ?>
                            <option value="{$key}" {$actived}>{$val}</option>
                        </foreach>
                    </select>
                    <label id="type-error" class="error" for="type"></label>
                    <!--<input type="text" class="inp" name="type" placeholder="请输入广告类型" title="请输入广告类型" required>-->
                </div>
                <div class="reportList"><span class="reportTit">广告结算步骤数：</span><input type="text" class="inp" name="clearing_num" placeholder="请输入广告结算步骤数" title="请输入广告结算步骤数" required value="{$ad['clearing_num']}"></div>
                <div class="reportList"><span class="reportTit">广告单价：</span><input type="text" class="inp" name="unit_price" placeholder="请输入广告单价" title="请输入广告单价" required value="{$ad['unit_price']}"></div>
                <div class="reportList"><span class="reportTit">广告总金额：</span><input type="text" class="inp" name="total_amount" placeholder="请输入广告总金额" title="请输入广告总金额" required value="{$ad['total_amount']}"></div>
                <div class="reportList"><span class="reportTit">广告消耗报警比例：</span><input type="text" class="inp" name="alarm_rate" placeholder="请输入广告消耗报警比例" title="请输入广告消耗报警比例" required value="{$ad['alarm_rate']}"></div>
                <div class="reportList"><span class="reportTit">ROI注册与投资转化率：</span><input type="text" class="inp" name="roi" placeholder="请输入ROI注册与投资转化率" title="请输入ROI注册与投资转化率" required value="{$ad['roi']}"></div>
                <div class="reportList"><span class="reportTit">特殊说明：</span><textarea class="inp" name="note" required placeholder="请输入特殊说明" title="请输入特殊说明">{$ad['note']}</textarea></div>

                <div class="reportList"><p class="subBtn" style="margin-top:15px;padding-left:155px"><input type="submit" value="提交" class="modifyBtn"></p></div>
            </div>
        </div>
    </form>
</div>


<script type="text/javascript">
    $(function() {
        //验证表单
        $("#addActivityForm").validate();
    });
</script>